package com.bw.base.net

import com.bw.base.entity.CodeSendEntity
import com.bw.base.entity.CouponEntity
import com.bw.base.entity.GoodsEntity
import com.bw.base.entity.IndexEntity
import com.bw.base.entity.LoginEntity
import com.bw.base.entity.Res
import com.bw.base.entity.UserInfoEntity
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query


interface Apiservice {
    //我们需要用协程方式请求数据   挂起函数可以被协程调用
    @POST(Cons.SEND_CODE_URL)
    suspend fun codeSend(@Query("phone") phone: String): Res<CodeSendEntity>

    //密码登录
    @POST(Cons.LOGIN_URL)
    suspend fun login(@Body requestBody: RequestBody): Res<LoginEntity>

    //验证码登录
    @POST(Cons.LOGIN_CODE_URL)
    suspend fun loginCode(@Body requestBody: RequestBody): Res<LoginEntity>

    //用户信息
    @GET(Cons.USER_INFO_URL)
    suspend fun userInfo(): Res<UserInfoEntity>

    //手机号修改密码
    @POST(Cons.UPDATE_PASSWORD_URL)
    suspend fun updatePwd(@Body requestBody: RequestBody): Res<Boolean>

    //首页数据
    @GET(Cons.INDEX_URL)
    suspend fun index(): Res<IndexEntity>

    //商品数据
    @GET(Cons.INDEX_GOODS_URL)
    suspend fun indexGoods(
        @Path("type") type: Int,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): Res<GoodsEntity>

    //优惠券
    @GET(Cons.COUPON_URL)
    suspend fun coupon(
        @Query("limit") limit: String,
        @Query("page") page: String,
        @Query("type") type: String
    ): Res<CouponEntity>
    //领取优惠券
    @POST(Cons.COUPON_RECEIVE_URL)
    suspend fun couponReceive(@Body requestBody: RequestBody):Res<String?>
}